<?php

namespace app\common\model\Product;

use think\Model;

class Type extends Model
{
    protected $name = 'product_type';

    protected $autoWriteTimestamp = false;

    protected $append = [
        'thumb_text',
    ];

    public function getThumbTextAttr($value, $data)
    {   
        $cdnurl = config('site.cdnurl');
        
        $thumb = isset($data['thumb']) ? $data['thumb'] : '';

        // 为空或文件不存在时给一个默认值
        if (empty($thumb) || !is_file('.' . $thumb)) {
            $thumb = "/assets/img/type.png";
        }

        return $cdnurl . $thumb;
    }
}
